package com.luanye.enjoy.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.luanye.enjoy.entity.Baike;
import com.luanye.enjoy.mapper.BaikeMapper;
import com.luanye.enjoy.service.BaikeService;
import com.luanye.enjoy.utils.BeanCopyUtils;
import com.luanye.enjoy.vo.BaikeVo;
import com.luanye.enjoy.vo.RespBean;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("baikeService")
@AllArgsConstructor
public class BaikeServiceImpl extends ServiceImpl<BaikeMapper, Baike> implements BaikeService {


    private final BaikeMapper baikeMapper;

    @Override
    public RespBean getByTypeId(Integer typeId) {
        LambdaQueryWrapper<Baike> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper.eq(Baike::getTypeid,typeId);

        List<Baike> baikes = baikeMapper.selectList(queryWrapper);

        List<BaikeVo> baikeVos = BeanCopyUtils.copyBeanList(baikes, BaikeVo.class);

        return RespBean.success(baikeVos);
    }


    @Override
    public RespBean getBreviaryById(Long id) {
        Baike baike = getById(id);

        BaikeVo baikeVo = BeanCopyUtils.copyBean(baike, BaikeVo.class);

        return RespBean.success(baikeVo);
    }
}
